﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Outpatient.Migrations
{
    /// <inheritdoc />
    public partial class add_table_OtpOrdRec : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_OtpOrdDetl_OtpOrd_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrd_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpPayRec_OtpOrd_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec");

            migrationBuilder.DropTable(
                name: "OtpOrd",
                schema: "Outpatient");

            migrationBuilder.CreateTable(
                name: "OtpOrdRec",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OrdBizSouc = table.Column<int>(type: "integer", nullable: false),
                    SetlTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    SetlTypeCode = table.Column<string>(type: "text", nullable: false),
                    SetlTypeName = table.Column<string>(type: "text", nullable: false),
                    OrdNo = table.Column<string>(type: "text", nullable: false),
                    Invono = table.Column<string>(type: "text", nullable: true),
                    OrdTitle = table.Column<string>(type: "text", nullable: false),
                    OrdExp = table.Column<string>(type: "text", nullable: false),
                    InvoAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    TotAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    DiscAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    RecAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    RecdAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    OrdStas = table.Column<int>(type: "integer", nullable: false),
                    FinlTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    CnclTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpOrdRec", x => x.Id);
                });

            migrationBuilder.AddForeignKey(
                name: "FK_OtpOrdDetl_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdDetl",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrdRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrdRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpPayRec_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrdRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_OtpOrdDetl_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpPayRec_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec");

            migrationBuilder.DropTable(
                name: "OtpOrdRec",
                schema: "Outpatient");

            migrationBuilder.CreateTable(
                name: "OtpOrd",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Cncltime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    DiscAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    Fintime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    InvoAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    Invono = table.Column<string>(type: "text", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    OrdBizSouc = table.Column<int>(type: "integer", nullable: false),
                    OrdExp = table.Column<string>(type: "text", nullable: false),
                    OrdName = table.Column<string>(type: "text", nullable: false),
                    OrdNo = table.Column<string>(type: "text", nullable: false),
                    OrdStas = table.Column<int>(type: "integer", nullable: false),
                    RecAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    RecdAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    TotAmt = table.Column<decimal>(type: "numeric", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpOrd", x => x.Id);
                });

            migrationBuilder.AddForeignKey(
                name: "FK_OtpOrdDetl_OtpOrd_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdDetl",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrd",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrd_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrd",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpPayRec_OtpOrd_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrd",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
